<!-- annotation validate -->
<template>
  <div>
    <button @click="excute">
      validate submit
    </button>
    &nbsp;
    <button @click="count += 1">
      Add
    </button>
    <div>
      count={{ count }}
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component } from "kaygnas-vue-property-decorator";
import { Validate, ValidateIntercept } from "@/annotations/validate";
import { ConfirmIntercept } from "@/annotations/confirm-intercept";
import { ErrorIntercept } from "@/annotations/error-intercept";
import MessageError from "@/errors/MessageError";

@Component({
  name: "Demo4",
})
export default class Demo4 extends Vue {

  public count: number = 0;

  @Validate("checkCount")
  public checkCount() {
    if (this.count === 0) {
      throw new MessageError("请添加数量")
    }
  }

  @ValidateIntercept("checkCount")
  @ConfirmIntercept("执行")
  @ErrorIntercept()
  public excute() {
    if (this.count < 3) {
      alert("执行成功");
    } else {
      throw new MessageError("执行数量过多");
    }
  }
}
</script>

